package provider;

import framework.rpc.protocol.http.server.HttpServer;
import framework.rpc.protocol.register.LocalRegister;
import framework.rpc.protocol.register.RegisterUrl;
import framework.rpc.protocol.register.RemoteMapRegister;
import provider.api.HellowService;
import provider.impl.HellowServiceImpl;

import java.net.InetAddress;

public class Provider {
    public static void main(String[] args) {
        //注册接口 HellowService有两个实现方法，此时需要调用哪一个，可以考虑使用版本号机制(注解实现)
        LocalRegister.register(HellowService.class.getName(), HellowServiceImpl.class, "1");

        try {
            //本机ip地址
            InetAddress localHost = InetAddress.getLocalHost();
            String hostName = localHost.getHostAddress();
            RegisterUrl registerUrl = new RegisterUrl(hostName, 8081);
            //服务注册（注册中心）:服务一旦启动，即可将信息注册进注册中心
            RemoteMapRegister.registry(HellowService.class.getName(), registerUrl);
            //启动、接收请求
            HttpServer httpServer = new HttpServer();
            httpServer.start(hostName, 8081);
        } catch (Exception e) {

        }

    }
}
